#define  _CRT_SECURE_NO_WARNINGS
class Solution {
public:
    int findSubstringInWraproundString(string s) {
        int n = s.size();
        vector<int> dp(n, 1);

        for (int i = 1; i < n; i++)
            if ((s[i - 1] == 'z' && s[i] == 'a') || (s[i - 1] + 1 == s[i]))
                dp[i] += dp[i - 1];
        vector<int> ret(26);
        for (int i = 0; i < n; i++)
            ret[s[i] - 'a'] = max(ret[s[i] - 'a'], dp[i]);

        int tmp = 0;
        for (int i = 0; i < 26; i++)
            tmp += ret[i];
        return tmp;
    }
};